package com.nbot.server.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nbot.server.domain.RelevancealarmDO;
import com.nbot.server.service.RelevancealarmService;
import com.nbot.server.util.PageUtils;
import com.nbot.server.util.Query;
import com.nbot.server.util.R;
import com.nbot.server.annotation.Log;

/**
 * 联动报警管理
 *
 * @author nbot
 * @email nbot@163.com
 * @date 2018-06-25 01:39:57
 */

@Controller
@RequestMapping("/server/relevancealarm")
public class RelevancealarmController {
    @Autowired
    private RelevancealarmService relevancealarmService;

    @GetMapping()
    @RequiresPermissions("server:relevancealarm:relevancealarm")
    String Relevancealarm() {
        return "server/relevancealarm/relevancealarm" ;
    }

    @ResponseBody
    @Log("查看联动报警管理")
    @GetMapping("/list")
    @RequiresPermissions("server:relevancealarm:relevancealarm")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<RelevancealarmDO> relevancealarmList = relevancealarmService.list(query);
        int total = relevancealarmService.count(query);
        PageUtils pageUtils = new PageUtils(relevancealarmList, total);
        return pageUtils;
    }

    @GetMapping("/add")
    @RequiresPermissions("server:relevancealarm:add")
    String add() {
        return "server/relevancealarm/add" ;
    }

    @GetMapping("/edit/{autoid}")
    @RequiresPermissions("server:relevancealarm:edit")
    String edit(@PathVariable("autoid") Long autoid, Model model) {
            RelevancealarmDO relevancealarm = relevancealarmService.get(autoid);
        model.addAttribute("relevancealarm" , relevancealarm);
        return "server/relevancealarm/edit" ;
    }

    /**
     * 保存
     */
    @Log("保存联动报警管理")
    @ResponseBody
    @PostMapping("/save")
    @RequiresPermissions("server:relevancealarm:add")
    public R save(RelevancealarmDO relevancealarm) {
        if (relevancealarmService.save(relevancealarm) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 修改
     */
    @Log("修改联动报警管理")
    @ResponseBody
    @RequestMapping("/update")
    @RequiresPermissions("server:relevancealarm:edit")
    public R update(RelevancealarmDO relevancealarm) {
            relevancealarmService.update(relevancealarm);
        return R.ok();
    }

    /**
     * 删除
     */
    @Log("删除联动报警管理")
    @PostMapping("/remove")
    @ResponseBody
    @RequiresPermissions("server:relevancealarm:remove")
    public R remove( Long autoid) {
        if (relevancealarmService.remove(autoid) > 0) {
            return R.ok();
        }
        return R.error();
    }

    /**
     * 删除
     */
    @Log("批量删除联动报警管理")
    @PostMapping("/batchRemove")
    @ResponseBody
    @RequiresPermissions("server:relevancealarm:batchRemove")
    public R remove(@RequestParam("ids[]") Long[]autoids) {
            relevancealarmService.batchRemove(autoids);
        return R.ok();
    }

}
